package com.ghost.UI
{
	import com.adobe.cairngorm.control.CairngormEventDispatcher;
	import com.ghost.event.Skin_Event;
	import com.ghost.model.UI_skin_data;
	
	import fl.events.ScrollEvent;
	
	import flash.display.DisplayObject;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;
	
	public class Ghost_list extends Sprite
	{
		private var mask_shape:Shape;//遮罩
		private var view_h:Number;//视域高度
		private var view_w:Number;//视域宽度
		private var bg_content:Sprite;//存放背景
		private var scroll_o:Ghost_scroll;//滚动条实例
		/**
		 * @param w 视域宽度
		 * @param h 视域高度
		 * @param content_o list内容容器
		 * @param scroll_w 滚动条宽度
		 * @param scroll_v 滚动条皮肤(up_arrow_btn,down_arrow_btn,thumb_btn,track_bg)
		 * @param bg_o 背景
		 */		
		public function Ghost_list(w:Number,h:Number,content_o:DisplayObject,scroll_w:Number,scroll_v:Vector.<Object>=null,bg_o:Class=null)
		{
			view_h = h;
			view_w = w;
			var content_h:Number = content_o.height;
			mask_shape = new Shape();
			mask_shape.graphics.beginFill(0xffffff);
			mask_shape.graphics.drawRect(0,0,w,h);
			mask_shape.visible = false;
			this.addChild(mask_shape);
			if(bg_o)
			{
				//背景存在
				bg_content = new Sprite();
				this.addChild(bg_content);
				var bg:DisplayObject = new bg_o();
				bg_content.addChild(bg);
				bg.width = view_w;
				bg.height = h;
			}
			if(h<content_h)
			{
				//需要滚动条
				scroll_o = new Ghost_scroll(scroll_v);
				this.addChild(scroll_o);
				scroll_o.width = scroll_w;
				scroll_o.height = h;
				scroll_o.x = w-scroll_o.width;
				scroll_o.addEventListener(ScrollEvent.SCROLL,scroll_Handler);
			}
			this.mask = mask_shape;
			this.addEventListener(Event.REMOVED_FROM_STAGE,remove_Handler);
			CairngormEventDispatcher.getInstance().addEventListener(Skin_Event.skin_change_event,change_Handler);//所有不同ui更换
		}
		private function scroll_Handler(e:ScrollEvent):void
		{
		}
		public function update(content_o:DisplayObject):void
		{
			
		}
		//移除此组件 
		private function remove_Handler(e:Event):void
		{
			this.removeEventListener(Event.REMOVED_FROM_STAGE,remove_Handler);
			CairngormEventDispatcher.getInstance().addEventListener(Skin_Event.skin_change_event,change_Handler);//所有不同ui更换
		}
		/**
		 * 按钮更换样式 e.data可以是数字 代表第几套皮肤
		 */		
		private function change_Handler(e:Skin_Event):void
		{
			if(bg_content)
			{
				bg_content.removeChildAt(0);
			}
			var bg_o:DisplayObject = new UI_skin_data.ghost_list_skin_v[e.data]();
			bg_o.width = view_w;
			bg_o.height = view_h;
			bg_content.addChild(bg_o);
		}
	}
}